<?php
require_once("./DButil.php");

// 角色维护

// $sql = "select r.roleId,r.roleName,p.powerName
// from t_role r
// left join t_role_power rp on r.roleId=rp.roleId
// left join t_power p on rp.powerId=p.powerId
// group by r.roleId
// ";
$sql1="select roleId,roleName from t_role";
$roleArr=query($sql1);
$roles=[];

foreach($roleArr as $r){
    $sql2="select p.powerId,p.powerName
    from t_power p
    join t_role_power rp on p.powerId =rp.powerId
    where rp.roleId={$r['roleId']}";
    $powers=query($sql2);
    $r["powers"]=$powers;
    $roles[]=$r;
}

header("Content-Type:application/json;charset=utf-8");
echo json_encode($roles);
?>